using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class JobSeekers_resumesearch : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "RecruitVietnam"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                Session["ResumeStatus"] = "Update";
                ShowResume();
            }
        }
    }
         
    void ShowResume()
    {
        SqlServerProvider cls = new SqlServerProvider(connectionString);
        cls.CommandText = 
        "select * from vwResumes " +
         " where UserID=@UserID";
        cls.ParameterCollection = 
        new string[1] { "@UserID" };
        cls.ValueCollection = new 
        string[1]{Convert.ToString(
        Session.Contents["jsuserid"])};
        DataTable dataTable = cls.GetDataTable();
        GridViewHelper helper = new GridViewHelper();
        helper.FillDataTableToGridView(
        dataTable, GridView1);        
        MakeDefaultValue();
        if (dataTable.Rows.Count > 0)
            btnNew.Enabled = true;
        else
            btnNew.Enabled = false;

    }

    void MakeDefaultValue( )
    {        
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            string viewable = gridViewRow.Cells[3].Text;

            DropDownList dropDownList =
            (DropDownList)
            gridViewRow.Cells[2].FindControl("ddlViewable");
            dropDownList.SelectedValue = viewable;                 

            if (gridViewRow.Cells[0].Text 
            == Session["jsresume"].ToString())
            {

                HyperLink hyperLinkField = (HyperLink)
                gridViewRow.Cells[1].Controls[0];
                hyperLinkField.Text += 
                " <img src=\"/icons/check.gif\""+
                " border=0 alt='Activate Resume'>";

            }     
        }
        this.GridView1.Columns[3].Visible = false;
    }
     
    bool SetResumeSearch()
    {
        bool update = false;
        try
        {
            string updateQuery = "";
            
                             
            foreach (GridViewRow item in GridView1.Rows)
            {
                DropDownList dropDownList = 
                (DropDownList)
                item.Cells[2].FindControl("ddlViewable");
                if(item.Cells[3].Text != dropDownList.SelectedValue)
                    updateQuery += 
                    "Update tblJSResumes set Viewable = " 
                    + dropDownList.SelectedValue +
                    " where UserID =@UserID and ResumeID='" 
                    + item.Cells[0].Text +"'";                   
                     
            }
            if (updateQuery != "")
            {
                SqlServerProvider cls = new 
                SqlServerProvider(connectionString);
                cls.CommandText =updateQuery ;
                cls.ParameterCollection = 
                new string[1] { "@UserID" };
                cls.ValueCollection = 
                new string[1]{
                Convert.ToString(
                Session.Contents["jsuserid"])};
                update = (cls.ExecuteNonQuery() > 0);
            }             
        }
        catch (Exception ex)
        {
            literalError.Text = ex.Message;
        }
        return update;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        SetResumeSearch();
    }
}
